<?php 
$chungloai = $tl->TheLoai_List();
$loai = $lt->LoaiTin_List();

if(isset($_POST[btnSumit])){		
	$thanhcong = $t->Tin_Them($loi);	
	if($thanhcong==true){
		
		header("location:?com=tin_list");
	}
}
?>
<link href="css/ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="ckfinder/ckfinder.js"></script>
<script type="text/javascript">
    var debounce =  function(func, wait, immediate) {
    var timeout, result;
    return function() {
      var context = this, args = arguments;
      var later = function() {
        timeout = null;
        if (!immediate) result = func.apply(context, args);
      };
      var callNow = immediate && !timeout;
      clearTimeout(timeout);
      timeout = setTimeout(later, wait);
      if (callNow) result = func.apply(context, args);
      return result;
    };
  };
    
    
	$(document).ready(function(){       
		$("input[name=TieuDe]").blur(function(){
			var TieuDe= $(this).val();
			$.post("blocks/ajax.php",{str:TieuDe},function(data){				
				$("input[name=TieuDe_KD]").val(data);
			})
		})
		
	});
function split(val) {
	return val.split(/;\s*/);
}

function extractLast(term) {
	return split(term).pop();
}	
</script>
<script type="text/javascript">
function BrowseServer( startupPath, functionData ){
	var finder = new CKFinder();
	finder.basePath = 'ckfinder/'; //Đường path nơi đặt ckfinder
	finder.startupPath = startupPath; //Đường path hiện sẵn cho user chọn file
	finder.selectActionFunction = SetFileField; // hàm sẽ được gọi khi 1 file được chọn
	finder.selectActionData = functionData; //id của text field cần hiện địa chỉ hình
	//finder.selectThumbnailActionFunction = ShowThumbnails; //hàm sẽ được gọi khi 1 file thumnail được chọn	
	finder.popup(); // Bật cửa sổ CKFinder
} //BrowseServer

function SetFileField( fileUrl, data ){
	document.getElementById( data["selectActionData"] ).value = fileUrl;
}
function ShowThumbnails( fileUrl, data ){	
	var sFileName = this.getSelectedFile().name; // this = CKFinderAPI
	document.getElementById( 'thumbnails' ).innerHTML +=
	'<div class="thumb">' +
	'<img src="' + fileUrl + '" />' +
	'<div class="caption">' +
	'<a href="' + data["fileUrl"] + '" target="_blank">' + sFileName + '</a> (' + data["fileSize"] + 'KB)' +
	'</div>' +
	'</div>';
	document.getElementById( 'preview' ).style.display = "";
	return false; // nếu là true thì ckfinder sẽ tự đóng lại khi 1 file thumnail được chọn
}
</script>

<form action="" method="post" name="form_add_dm_ks">
<div id="admin_navigation">
	<div style="float:left;width:90%">
		<h3>Quản lý bài viết: Thêm mới</h3>
    </div>
	<div style="float:left;width:5%;padding-top:5px">
    	<input type="submit" class="save" name="btnSumit" value=""/><br />		
        <span>Save</span>
    </div>
    <div style="float:left;width:5%;padding-top:5px">
    	<input type="reset" class="cancel" name="btnCancel" value=""/><br />		
        <span>Reset</span>
    </div>
    <div class="clr"></div>
    <div style="clear:both"></div>
</div>
    <div style="clear:both"></div>
<div id="main_admin">
	
	<div id="main_left">
    	<fieldset>
        	<legend>Thông tin chung</legend>
            	<table>                   
                              
                    <tr class="left">
                    	<td>Tiêu đề</td>
                        <td><input type="text" name="TieuDe" id="TieuDe" class="tf" value="<?php echo $_POST['TieuDe']?>" style="width:300px" />
                        	<span class="error"><?php echo $loi['TieuDe'];?></span>
                        </td>                        
                    </tr>
                    <tr class="left">
                    	<td>Tiêu đề KD</td>
                        <td>
                        	<input type="text" name="TieuDe_KD" id="TieuDe_KD" class="tf" value="<?php echo $_POST['TieuDe_KD']?>" style="width:300px" />				                        </td>                        
                    </tr>
                    <tr>
                    <td class="left">Ẩn/Hiện</td>
                        <td>
                            <label>
                            <input type="radio" name="AnHien" value="1" id="AnHien_1"  checked="checked"/>
                        Hiện</label>
                            <label>
                            <input type="radio" name="AnHien" value="0" id="AnHien_0"  />
                            Ẩn</label>

                        </td>                        
                    </tr>     
                    <tr>
                        <td>Hình đại diện</td>
                        <td><input type="text" name="UrlHinh" id="UrlHinh" class="tf" value="<?php echo $_POST[UrlHinh]?>"/>
                            <input type="button" name="btnChonFile" value="Chọn hình" onclick="BrowseServer('Images:/','UrlHinh')"  />                       
                        </td>                        
                    </tr> 
                              
                </table>            
        </fieldset>
    </div>
	<div id="main_right">
    	
    </div>
   
    <div id="main_details" style="clear:both;padding-top: 20px">
        <fieldset class="details_form">
        	<legend>++ Nội dung bài viết ++</legend>
            <table>                          
                <tr>
                    <td>Mô tả</td>
                    <td>
                        <textarea style="height:100px;width:500px" class="meta" name="TomTat" id="TomTat" rows="10"><?php echo $_POST[TomTat]?></textarea>                       
                    </td>                        
                </tr>               
                
                <tr>
                    <td>Chi tiết</td>
                    <td><div style="width:800px;overflow: hidden">
                        <textarea class="meta" name="NoiDung" id="NoiDung"><?php echo $_POST[NoiDung]?></textarea>
                        <script type="text/javascript">
                        var editor = CKEDITOR.replace( 'NoiDung',{
                            uiColor : '#9AB8F3',
                            language:'vi',
                            skin:'office2003',
                            filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
                            filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
                            filebrowserImageUploadUrl :'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
                            filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',

                            toolbar:[
                            ['Source','-','Save'],
                            ['Copy','Paste','PasteText','PasteFromWord'],
                            ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
                            ['NumberedList','BulletedList'],
                            ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
                            ['Link','Unlink','Anchor','Image'],                           
                            ['Styles','Format','Font','FontSize'],
                            ['TextColor','BGColor']                         
                            ]
                        });		
                        </script>
                        </div>
                    </td>                        
                </tr>                                   
            </table>
        </fieldset>
        
    </div>
   
    <div class="clr"></div>
</div>
</form>
<script type="text/javascript" src="js/form.js"></script>
<script type="text/javascript" src="js/core.js"></script>
<script type="text/javascript" src="js/widget.js"></script>
<script type="text/javascript" src="js/custom.js"></script>